CLIP.Search.enc = function(val) {
	return val.replace(/ /g, '+');
};

CLIP.Search.dec = function(val) {
	return val.replace(/\+/g, ' ');
};

CLIP.Clips.initPage = 0;
CLIP.Clips.currentPage = 0;
CLIP.Clips.pageSize = 15;

CLIP.Clips.searchUrl = function(keyword) {
	return 'http://m.phim.clip.vn/search?p=' + (CLIP.Clips.currentPage + 1) + '&keyword=' + encodeURIComponent(keyword);
};

CLIP.Clips.filterUrl = function() {
	return 'http://m.phim.clip.vn/film/ajaxLoadMoreFilm?' + $('#filterForm').serialize();
};

CLIP.Clips.moreHtml = function(text) {
	var html = [];
	$.each(text.split('<li class="item clearfix"'), function(i, clip) {
		if (i > 0) {
			++CLIP.Clips.moreCount;
			;
			var code = bum.util.parse(clip, '<a href="', '"').replace('http://m.phim.clip.vn', '').replace('/info/', '');
			var title = bum.util.parse(clip, '<span class="title">', '</span>');
			var originalTitle = bum.util.parse(clip, '<span class="title-original">', '</span>');
			var img = bum.util.parse(clip, 'src="', '"');

			html.push('<a class="item clip" href="#" code="', code, '"><div class="cw">');
			html.push('<img src="http://cdn.bum.vn/_.gif" style="background-image:url(', img, ');"/>');
			html.push('<div class="iw"><h4>', title, '</h4>');
			html.push('<h5>', originalTitle, '</h5></div>');
			html.push('</div></a>');
		}
	});
	return html;
};

CLIP.Info.infoUrl = function(code) {
	return 'http://m.phim.clip.vn/info/' + code;
};

CLIP.Info.parseInfo = function(text) {
	text = bum.util.parse(text, '<div class="wapper-film">', '<div id="filmtrailer" class="tab-pane fade">');
	if (text == null) {
		return null;
	}

	var poster = bum.util.parse(text, 'src="', '"');
	var title = bum.util.parse(text, '<span class="title">', '</span>');
	var originalTitle = bum.util.parse(text, '<span class="title-original">', '</span>');

	var intro = bum.util.parse(text, '<div id="filminfo" class="tab-pane fade active in">', '<!-- End .film-desc-->').replace(/<[\/]{0,1}(iframe|a|font)[^><]*>/gi, "").replace(/style/g, 'styles')
			.replace(/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi, '');

	var chaps = [];
	var eps = bum.util.parse(text, '<div class="swiper-wrapper">', '<ul class="nav nav-tabs" id="myTab">');
	if (eps) {
		$.each(eps.split('<div class="item swiper-slide ">'), function(i, list) {
			if (i > 0) {
				var code = bum.util.parse(list, ',', '"');
				var name = bum.util.parse(list, '">', '</a>');
				chaps.push('<a href="' + code + '">' + name + '</a>');
			}
		});
	}

	var clip = {
		poster : poster,
		title : title,
		originalTitle : originalTitle,
		intro : intro,
		chaps : chaps
	};

	return clip;
};


CLIP.Chap.headers = [ 'Accept', 'text/plain, text/html', 'Host', 'm.phim.clip.vn', 'Cache-Control', 'max-age=0', 'Connection', 'close', 'User-Agent',
		'Mozilla/5.0 (Linux; U; Android 2.2; en-us; DROID2 GLOBAL Build/S273) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1' ].join('|');

CLIP.Chap.flashHeaders = [ 'Accept', 'text/plain, text/html', 'Host', 'clip.vn', 'Cache-Control', 'max-age=0', 'Connection', 'close', 'User-Agent',
              		'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/38.0.2125.101 Safari/537.36' ].join('|');

CLIP.Chap.load = function(code) {
	bum.api.fetchHttpUrl('http://clip.vn/movies/nfo/' + code.split('/')[0], 'POST', 'onsite=clip&referrer:aHR0cDovL3BoaW0uY2xpcC52bi93YXRjaC9EaW5oLU1lbmgvMjgwMTk=', CLIP.Chap.flashHeaders, CLIP.Chap.getChap);
};

// custome
CLIP.Chap.streamUrl = function(text) {
	text = bum.util.parse(text, "enclosure url='", "'");
	return text;
};